package client;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;

import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.JTextPane;
import javax.swing.text.AttributeSet;
import javax.swing.text.BadLocationException;
import javax.swing.text.Document;
import javax.swing.text.SimpleAttributeSet;
import javax.swing.text.StyleConstants;



public class UserChatWindow extends JPanel{		
	
	JTextField tfTxt = new JTextField();
	private JTextPane taContent = new JTextPane();	
	private String userName = null;
	
	public UserChatWindow(String userName){
		this.userName = userName;
	}
	/**
	 * paint the frame.
	 *
	 */
	public void launchFrame() {		
		this.setName(userName + "'s ChatWindows.");
		this.setLocation(400, 300);
		this.setPreferredSize(new Dimension(350, 400));
		//this.setSize(450, 300);
		taContent.setPreferredSize(new Dimension(350, 360));
		taContent.setEditable(false);
		tfTxt.setPreferredSize(new Dimension(350, 30));
		this.setLayout(new BorderLayout());		
		this.add(tfTxt, BorderLayout.SOUTH);
		this.add(new JScrollPane(taContent), BorderLayout.NORTH);
		//this.pack();		
		//this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		//this.setVisible(true);		
	}
	/**
	 * insert a string into doc.
	 * @param str
	 */
	public void insert(String str, AttributeSet attrset){
		Document docs = taContent.getDocument();
		str = str + "\n";
		try {
			docs.insertString(docs.getLength(), str, attrset);
		} catch (BadLocationException e) {			
			e.printStackTrace();
		}
	}
	/**
	 * display the sentences.
	 * @param str
	 * @param font
	 */
	public void displaySays(String str, UserFonts font){
		SimpleAttributeSet attrset = new SimpleAttributeSet();
		StyleConstants.setForeground(attrset, font.getColor());
		StyleConstants.setBold(attrset, font.getBold());
		StyleConstants.setFontSize(attrset, font.getSize());
		StyleConstants.setUnderline(attrset, font.getUnderLine());
		insert(str,attrset);
	}			
}
